<script setup lang="ts">
import { ref } from 'vue'
import { getBusinessInfoByUseridAPI } from '@/api/business'
import type { ApplyBusiness } from '@/types/business'
import { onLoad } from '@dcloudio/uni-app'
import { baseURL } from '@/utils/http'

const query = defineProps<{
  id: string
}>()
// 获取企业信息
const companyInfo = ref<ApplyBusiness>()
const getCompanyInfo = async () => {
  const res = await getBusinessInfoByUseridAPI(query.id)
  companyInfo.value = res.data
  console.log(companyInfo.value)
}
onLoad(() => {
  if (query.id) {
    getCompanyInfo()
  } else {
    uni.showToast({ icon: 'none', title: '您还没有商户权限，请注册账号！'})
  }
})

const onSubmit = () => {
  // uni.navigateTo({url:`/pages/join/join?id=${query.id}`})
  uni.showToast({ icon: 'none', title: '请联系管理员修改信息！'})
}
</script>

<template>
  <!-- 表单 -->
  <view class="form">
    <!-- 表单内容 -->
    <view class="form-content">
      <view class="form-item" v-if="companyInfo?.typeName">
        <text class="label">商家类型</text>
        <text class="info">{{ companyInfo?.typeName }}</text>
      </view>
      <view class="form-item" v-if="companyInfo?.name">
        <text class="label">公司名称</text>
        <text class="info">{{ companyInfo?.name }}</text>
      </view>
      <view class="form-item" v-if="companyInfo?.shortName">
        <text class="label">公司简称</text>
        <text class="info">{{ companyInfo?.shortName }}</text>
      </view>
      <view class="form-item" v-if="companyInfo?.businessLicense">
        <text class="label">营业执照号</text>
        <text class="info">{{ companyInfo?.businessLicense }}</text>
      </view>
      <view class="form-item image_upload" v-if="companyInfo?.businessLicenseUrl">
        <text class="label">营业执照</text>
        <view class="upload">
          <image :src="baseURL + companyInfo?.businessLicenseUrl" mode="aspectFill" />
        </view>
      </view>
      <!-- <view class="form-item image_upload">
        <text class="label">企业照片</text>
        <view class="upload">
          <image :src="baseURL + companyInfo?.imageUrl" mode="aspectFill" />
        </view>
      </view> -->
      <view class="form-item" v-if="companyInfo?.industry">
        <text class="label">所属行业</text>
        <text class="info">{{ companyInfo?.industry }}</text>
      </view>
      <view class="form-item" v-if="companyInfo?.areaName">
        <text class="label">城市</text>
        <text class="info">{{ companyInfo?.areaName }}</text>
      </view>
      <view class="form-item" v-if="companyInfo?.address">
        <text class="label">地址</text>
        <text class="info">{{ companyInfo?.address }}</text>
      </view>
      <uni-section title="实名认证" type="line">
        <view class="form-item">
          <text class="label">负责人姓名</text>
          <text class="info">{{ companyInfo?.contacts }}</text>
        </view>
        <view class="form-item">
          <text class="label">身份证号</text>
          <text class="info">{{ companyInfo?.idCard }}</text>
        </view>
        <view class="form-item image_upload">
          <text class="label">身份证正面</text>
          <view class="upload">
            <image :src="baseURL + companyInfo?.frontCardImage" mode="aspectFill" />
          </view>
        </view>
        <view class="form-item image_upload">
          <text class="label">身份证背面</text>
          <view class="upload">
            <image :src="baseURL + companyInfo?.backCardImage" mode="aspectFill" />
          </view>
        </view>
        <view class="form-item">
          <text class="label">电话号码</text>
          <text class="info">{{ companyInfo?.contactsPhone }}</text>
        </view>
      </uni-section>
    </view>
    <!-- 提交按钮 -->
    <button class="form-button" @tap="onSubmit">修改信息</button>
  </view>
</template>

<style lang="scss">
.profile {
  padding: 60rpx 0 60rpx;
  position: relative;
  background-color: rgb(0, 206, 170);
  color: #fff;
  text-align: center;
}
.upload {
  padding-top: 0;
  border-radius: 10px;
  border: none;
}
.form {
  height: auto;
  padding-bottom: 20px;
}
</style>
